import { legacy_createStore as createStore, combineReducers, applyMiddleware } from 'redux';
// 引入 useReducer 纯函数
import userReducer from './user/userReducer';
// redux 日志插件
import logger from 'redux-logger'
import { l } from '../utils'
// 合并 reducer
const reducer = combineReducers({
	// 用户库
	user: userReducer
})

// 创建仓库             
const store = createStore(reducer, applyMiddleware(logger));

// 获取仓库的类型
export type RootState = ReturnType<typeof store.getState>

// 订阅仓库  每一次dispatch action 的时候 这个订阅回调函数会执行
store.subscribe(() => {
	const state = store.getState();
	l.setItem('token', state.user.token)
})
export default store